Pro Membership
//If user is an admin allow access.
if( current_user_can( 'manage_options' ) ){
$hasaccess = true;
}
return $hasaccess;
}
add_filter('pmpro_has_membership_access_filter', 'pmmpro_allow_access_for_admins', 30, 4);
Pro Membership
<?php function my_redirect_nonmembers() {
// Make sure PMPro is active.
if ( ! function_exists( 'pmpro_hasMembershipLevel' ) ) {
return;
}
// Ignore members. Change to check for specific levels.
if ( pmpro_hasMembershipLevel() ) {
return;
}
global $post;
if( ! is_admin() && ! empty( $post->ID ) ) {
if( $post->post_type == "page" || $post->post_type == "podcast-video" ) {
//check if the user has access to the parent
if( ! pmpro_has_membership_access( $post->ID ) ) {
wp_redirect( pmpro_url( "levels" ) );
exit;
}
}
}
// Update this array.
$not_allowed = array(
"/members/",
"/groups/",
"/groups/create/",
);
// Get the current URI.
$uri = $_SERVER['REQUEST_URI'];
// If we're on one of those URLs, redirect away.
foreach( $not_allowed as $check ) {
if( strpos( strtolower( $uri ), strtolower( $check ) ) !== false ) {
// Go to levels page. Change if wanted.
wp_redirect( pmpro_url( 'levels' ) );
exit;
}
}
}
add_action( 'template_redirect', 'my_redirect_nonmembers' );
jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. With a combination of versatility and extensibility, jQuery has changed the way that millions of people write JavaScript.
An API key is used by a lot of Web API to provide a form of access control. The key usually is linked to the identity of the API user as well as bundle of rights like a quota or areas of the APIs which are open for access to that key
<?php// get the HTTP method, path and body of the request$method = $_SERVER['REQUEST_METHOD'];$request = explode('/', trim($_SERVER['PATH_INFO'],'/'));$input = json_decode(file_get_contents('php://input'),true);// connect to the mysql database$link = mysqli_connect('localhost', 'root', 'root', 'myDB');mysqli_set_charset($link,'utf8');// retrieve the table and key from the path$table = preg_replace('/[^a-z0-9_]+/i','',array_shift($request));$key = array_shift($request)+0;// escape the columns and values from the input object$columns = preg_replace('/[^a-z0-9_]+/i','',array_keys($input));$values = array_map(function ($value) use ($link) {if ($value===null) return null;return mysqli_real_escape_string($link,(string)$value);},array_values($input));// build the SET part of the SQL command$set = '';for ($i=0;$i<count($columns);$i++) {$set.=($i>0?',':'').'`'.$columns[$i].'`=';$set.=($values[$i]===null?'NULL':'"'.$values[$i].'"');}// create SQL based on HTTP methodswitch ($method) {case 'GET':$sql = "select * from `myform`".($key?" WHERE id=$key":''); break;case 'PUT':$sql = "update `myform` set $set where id=$key"; break;case 'POST':$sql = "insert into `myform` set $set"; break;case 'DELETE':$sql = "delete `myform` where id=$key"; break;}// excecute SQL statement$result = mysqli_query($link,$sql);// die if SQL statement failedif (!$result) {http_response_code(404);die(mysqli_error());}// print results, insert id or affected row countif ($method == 'GET') {if (!$key) echo '[';for ($i=0;$i<mysqli_num_rows($result);$i++) {echo ($i>0?',':'').json_encode(mysqli_fetch_object($result));}if (!$key) echo ']';} elseif ($method == 'POST') {echo mysqli_insert_id($link);} else {echo mysqli_affected_rows($link);}// close mysql connectionmysqli_close($link);?>
If you want to delete a record from any MySQL table, then you can use the SQL command DELETE FROM. You can use this command at the mysql> prompt as well as in any script like PHP.
DELETE FROM table_name [WHERE Clause]
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ) {
die('Could not connect: ' . mysql_error());
}
$sql = 'DELETE FROM tutorials_tbl WHERE tutorial_id = 3';
mysql_select_db('TUTORIALS');
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not delete data: ' . mysql_error());
}
echo "Deleted data successfully\n";
mysql_close($conn);
?>
The SQL DELETE command is used to delete rows that are no longer required from the database tables. It deletes the whole row from the table. Delete command comes in handy to delete temporary or obsolete data from your database.The DELETE command can delete more than one row from a table in a single query. This proves to be advantages when removing large numbers of rows from a database table.
DELETE FROM table_name [WHERE Clause]
root@host# mysql -u root -p password; Enter password:******* mysql> use TUTORIALS; Database changed mysql> DELETE FROM tutorials_tbl WHERE tutorial_id=3; Query OK, 1 row affected (0.23 sec) mysql>
<?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } $sql = 'DELETE FROM tutorials_tbl WHERE tutorial_id = 3'; mysql_select_db('TUTORIALS'); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not delete data: ' . mysql_error()); } echo "Deleted data successfully\n"; mysql_close($conn); ?>
There may be a requirement where the existing data in a MySQL table needs to be modified. You can do so by using the SQL UPDATE command. This will modify any field value of any MySQL table.
<?php
$server = 'localhost';
$username = 'root';
$password = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ) {
die('Could not connect: ' . mysql_error());
}
$sql = 'UPDATE tutorials_tbl
SET tutorial_title="Learning JAVA"
WHERE tutorial_id=3';
mysql_select_db('TUTORIALS');
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
mysql_close($conn);
?>
PHP stands for Hypertext Preprocessor. PHP is a powerful and widely-used open source server-side scripting language to write dynamically generated web pages. PHP scripts are executed on the server and the result is sent to the browser as plain HTML.
There may be a requirement where the existing data in a MySQL table needs to be modified. You can do so by using the SQL UPDATE command. This will modify any field value of any MySQL table.
View this post on Instagram A post shared by WebCodeAddict (@webcodeaddicted)