Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Plugin Name: SEO Keen Functionality
- * Plugin URI: http://www.keen.com.mt
- * Description: Extra functionality for SEO Keen.
- * Version: 1.0
- * Author: Keen Ltd.
- * Author URI: http://www.keen.com.mt
- */
- ini_set('max_execution_time', 500);
- //Register Publisher CPT
- function publisher_cpt()
- {
- $labels = array(
- 'name' => _x( 'Publishers', 'Post Type General Name', 'ax-front' ),
- 'singular_name' => _x( 'Publisher', 'Post Type Singular Name', 'ax-front' ),
- 'menu_name' => __( 'Publishers', 'ax-front' ),
- 'name_admin_bar' => __( 'Publisher', 'ax-front' ),
- 'archives' => __( 'Publisher Archives', 'ax-front' ),
- 'attributes' => __( 'Publisher Attributes', 'ax-front' ),
- 'parent_item_colon' => __( 'Parent Publisher:', 'ax-front' ),
- 'all_items' => __( 'All Publishers', 'ax-front' ),
- 'add_new_item' => __( 'Add New Publisher', 'ax-front' ),
- 'add_new' => __( 'Add New', 'ax-front' ),
- 'new_item' => __( 'New Publisher', 'ax-front' ),
- 'edit_item' => __( 'Edit Publisher', 'ax-front' ),
- 'update_item' => __( 'Update Publisher', 'ax-front' ),
- 'view_item' => __( 'View Publisher', 'ax-front' ),
- 'view_items' => __( 'View Publisher', 'ax-front' ),
- 'search_items' => __( 'Search Publishers', 'ax-front' ),
- 'not_found' => __( 'Not found', 'ax-front' ),
- 'not_found_in_trash' => __( 'Not found in Trash', 'ax-front' ),
- 'featured_image' => __( 'Featured Image', 'ax-front' ),
- 'set_featured_image' => __( 'Set featured image', 'ax-front' ),
- 'remove_featured_image' => __( 'Remove featured image', 'ax-front' ),
- 'use_featured_image' => __( 'Use as featured image', 'ax-front' ),
- 'insert_into_item' => __( 'Insert into event', 'ax-front' ),
- 'uploaded_to_this_item' => __( 'Uploaded to this event', 'ax-front' ),
- 'items_list' => __( 'Publisher list', 'ax-front' ),
- 'items_list_navigation' => __( 'Publisher list navigation', 'ax-front' ),
- 'filter_items_list' => __( 'Filter Publisher list', 'ax-front' ),
- );
- register_post_type('publisher',
- array(
- 'labels' => $labels,
- 'public' => true,
- 'show_in_rest'=> true,
- 'menu_icon' => "dashicons-welcome-view-site",
- 'menu_position' => 6,
- 'rewrite' => array(
- 'slug' => 'publisher',
- 'with_front' => false
- ),
- 'supports' => array( 'title' ),
- )
- );
- }
- add_action('init', 'publisher_cpt');
- function publisher_categories_taxonomy() {
- register_taxonomy(
- 'category', // The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
- 'publisher', // post type name
- array(
- 'hierarchical' => true,
- 'label' => 'Categories', // display name
- 'query_var' => true,
- 'rewrite' => array(
- 'slug' => 'category', // This controls the base slug that will display before each term
- 'with_front' => false // Don't display the category base before
- )
- )
- );
- }
- add_action( 'init', 'publisher_categories_taxonomy');
- //Register Links CPT
- function link_cpt()
- {
- $labels = array(
- 'name' => _x( 'Links', 'Post Type General Name', 'ax-front' ),
- 'singular_name' => _x( 'Link', 'Post Type Singular Name', 'ax-front' ),
- 'menu_name' => __( 'Links', 'ax-front' ),
- 'name_admin_bar' => __( 'Link', 'ax-front' ),
- 'archives' => __( 'Link Archives', 'ax-front' ),
- 'attributes' => __( 'Link Attributes', 'ax-front' ),
- 'parent_item_colon' => __( 'Parent Link:', 'ax-front' ),
- 'all_items' => __( 'All Links', 'ax-front' ),
- 'add_new_item' => __( 'Add New Link', 'ax-front' ),
- 'add_new' => __( 'Add New', 'ax-front' ),
- 'new_item' => __( 'New Link', 'ax-front' ),
- 'edit_item' => __( 'Edit Link', 'ax-front' ),
- 'update_item' => __( 'Update Link', 'ax-front' ),
- 'view_item' => __( 'View Link', 'ax-front' ),
- 'view_items' => __( 'View Link', 'ax-front' ),
- 'search_items' => __( 'Search Links', 'ax-front' ),
- 'not_found' => __( 'Not found', 'ax-front' ),
- 'not_found_in_trash' => __( 'Not found in Trash', 'ax-front' ),
- 'featured_image' => __( 'Featured Image', 'ax-front' ),
- 'set_featured_image' => __( 'Set featured image', 'ax-front' ),
- 'remove_featured_image' => __( 'Remove featured image', 'ax-front' ),
- 'use_featured_image' => __( 'Use as featured image', 'ax-front' ),
- 'insert_into_item' => __( 'Insert into event', 'ax-front' ),
- 'uploaded_to_this_item' => __( 'Uploaded to this event', 'ax-front' ),
- 'items_list' => __( 'Link list', 'ax-front' ),
- 'items_list_navigation' => __( 'Link list navigation', 'ax-front' ),
- 'filter_items_list' => __( 'Filter Link list', 'ax-front' ),
- );
- register_post_type('link',
- array(
- 'labels' => $labels,
- 'public' => true,
- 'show_in_rest'=> true,
- 'menu_icon' => "dashicons-admin-links",
- 'menu_position' => 6,
- 'capabilities' => array(
- 'edit_post' => 'edit_link',
- 'edit_posts' => 'edit_links',
- 'edit_others_posts' => 'edit_other_links',
- 'publish_posts' => 'publish_links',
- 'read_post' => 'read_link',
- 'read_private_posts' => 'read_private_links',
- 'delete_post' => 'delete_link',
- 'delete_posts' => 'delete_links',
- ),
- 'rewrite' => array(
- 'slug' => 'link',
- 'with_front' => false
- ),
- 'supports' => array( 'title' ),
- )
- );
- }
- add_action('init', 'link_cpt');
- function sources_taxonomy() {
- register_taxonomy(
- 'source', // The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
- 'link', // post type name
- array(
- 'hierarchical' => true,
- 'label' => 'Sources', // display name
- 'query_var' => true,
- 'rewrite' => array(
- 'slug' => 'source', // This controls the base slug that will display before each term
- 'with_front' => false // Don't display the category base before
- )
- )
- );
- }
- add_action( 'init', 'sources_taxonomy');
- //Register Request CPT
- function request_cpt()
- {
- $labels = array(
- 'name' => _x( 'Requests', 'Post Type General Name', 'ax-front' ),
- 'singular_name' => _x( 'Request', 'Post Type Singular Name', 'ax-front' ),
- 'menu_name' => __( 'Requests', 'ax-front' ),
- 'name_admin_bar' => __( 'Request', 'ax-front' ),
- 'archives' => __( 'Request Archives', 'ax-front' ),
- 'attributes' => __( 'Request Attributes', 'ax-front' ),
- 'parent_item_colon' => __( 'Parent Request:', 'ax-front' ),
- 'all_items' => __( 'All Requests', 'ax-front' ),
- 'add_new_item' => __( 'Add New Request', 'ax-front' ),
- 'add_new' => __( 'Add New', 'ax-front' ),
- 'new_item' => __( 'New Request', 'ax-front' ),
- 'edit_item' => __( 'Edit Request', 'ax-front' ),
- 'update_item' => __( 'Update Request', 'ax-front' ),
- 'view_item' => __( 'View Request', 'ax-front' ),
- 'view_items' => __( 'View Request', 'ax-front' ),
- 'search_items' => __( 'Search Request', 'ax-front' ),
- 'not_found' => __( 'Not found', 'ax-front' ),
- 'not_found_in_trash' => __( 'Not found in Trash', 'ax-front' ),
- 'featured_image' => __( 'Featured Image', 'ax-front' ),
- 'set_featured_image' => __( 'Set featured image', 'ax-front' ),
- 'remove_featured_image' => __( 'Remove featured image', 'ax-front' ),
- 'use_featured_image' => __( 'Use as featured image', 'ax-front' ),
- 'insert_into_item' => __( 'Insert into event', 'ax-front' ),
- 'uploaded_to_this_item' => __( 'Uploaded to this event', 'ax-front' ),
- 'items_list' => __( 'Requests list', 'ax-front' ),
- 'items_list_navigation' => __( 'Requests list navigation', 'ax-front' ),
- 'filter_items_list' => __( 'Filter Requests list', 'ax-front' ),
- );
- register_post_type('request',
- array(
- 'labels' => $labels,
- 'public' => true,
- 'publicly_queryable' => false,
- 'show_in_rest'=> true,
- 'menu_icon' => "dashicons-lightbulb",
- 'menu_position' => 6,
- 'rewrite' => array(
- 'slug' => 'request',
- 'with_front' => false
- ),
- 'supports' => array( 'title' ),
- )
- );
- }
- add_action('init', 'request_cpt');
- //Register Task CPT
- // function task_cpt()
- // {
- // $labels = array(
- // 'name' => _x( 'Tasks', 'Post Type General Name', 'ax-front' ),
- // 'singular_name' => _x( 'Task', 'Post Type Singular Name', 'ax-front' ),
- // 'menu_name' => __( 'Tasks', 'ax-front' ),
- // 'name_admin_bar' => __( 'Task', 'ax-front' ),
- // 'archives' => __( 'Task Archives', 'ax-front' ),
- // 'attributes' => __( 'Task Attributes', 'ax-front' ),
- // 'parent_item_colon' => __( 'Parent Task:', 'ax-front' ),
- // 'all_items' => __( 'All Tasks', 'ax-front' ),
- // 'add_new_item' => __( 'Add New Task', 'ax-front' ),
- // 'add_new' => __( 'Add New', 'ax-front' ),
- // 'new_item' => __( 'New Task', 'ax-front' ),
- // 'edit_item' => __( 'Edit Task', 'ax-front' ),
- // 'update_item' => __( 'Update Task', 'ax-front' ),
- // 'view_item' => __( 'View Task', 'ax-front' ),
- // 'view_items' => __( 'View Task', 'ax-front' ),
- // 'search_items' => __( 'Search Task', 'ax-front' ),
- // 'not_found' => __( 'Not found', 'ax-front' ),
- // 'not_found_in_trash' => __( 'Not found in Trash', 'ax-front' ),
- // 'featured_image' => __( 'Featured Image', 'ax-front' ),
- // 'set_featured_image' => __( 'Set featured image', 'ax-front' ),
- // 'remove_featured_image' => __( 'Remove featured image', 'ax-front' ),
- // 'use_featured_image' => __( 'Use as featured image', 'ax-front' ),
- // 'insert_into_item' => __( 'Insert into event', 'ax-front' ),
- // 'uploaded_to_this_item' => __( 'Uploaded to this event', 'ax-front' ),
- // 'items_list' => __( 'Tasks list', 'ax-front' ),
- // 'items_list_navigation' => __( 'Tasks list navigation', 'ax-front' ),
- // 'filter_items_list' => __( 'Filter Tasks list', 'ax-front' ),
- // );
- // register_post_type('task',
- // array(
- // 'labels' => $labels,
- // 'public' => true,
- // 'publicly_queryable' => true,
- // 'show_in_rest'=> true,
- // 'menu_icon' => "dashicons-yes-alt",
- // 'menu_position' => 6,
- // 'capabilities' => array(
- // 'edit_post' => 'edit_task',
- // 'edit_posts' => 'edit_tasks',
- // 'edit_others_posts' => 'edit_other_tasks',
- // 'publish_posts' => 'publish_tasks',
- // 'read_post' => 'read_task',
- // 'read_private_posts' => 'read_private_tasks',
- // 'delete_post' => 'delete_task',
- // 'delete_posts' => 'delete_tasks',
- // ),
- // 'rewrite' => array(
- // 'slug' => 'task',
- // 'with_front' => false
- // ),
- // 'supports' => array( 'title' ),
- // )
- // );
- // }
- // add_action('init', 'task_cpt');
- //Register Invoice CPT
- function invoice_cpt()
- {
- $labels = array(
- 'name' => _x( 'Invoices', 'Post Type General Name', 'ax-front' ),
- 'singular_name' => _x( 'Invoice', 'Post Type Singular Name', 'ax-front' ),
- 'menu_name' => __( 'Invoices', 'ax-front' ),
- 'name_admin_bar' => __( 'Invoice', 'ax-front' ),
- 'archives' => __( 'Invoice Archives', 'ax-front' ),
- 'attributes' => __( 'Invoice Attributes', 'ax-front' ),
- 'parent_item_colon' => __( 'Parent Invoice:', 'ax-front' ),
- 'all_items' => __( 'All Invoices', 'ax-front' ),
- 'add_new_item' => __( 'Add New Invoice', 'ax-front' ),
- 'add_new' => __( 'Add New', 'ax-front' ),
- 'new_item' => __( 'New Invoice', 'ax-front' ),
- 'edit_item' => __( 'Edit Invoice', 'ax-front' ),
- 'update_item' => __( 'Update Invoice', 'ax-front' ),
- 'view_item' => __( 'View Invoice', 'ax-front' ),
- 'view_items' => __( 'View Invoice', 'ax-front' ),
- 'search_items' => __( 'Search Invoice', 'ax-front' ),
- 'not_found' => __( 'Not found', 'ax-front' ),
- 'not_found_in_trash' => __( 'Not found in Trash', 'ax-front' ),
- 'featured_image' => __( 'Featured Image', 'ax-front' ),
- 'set_featured_image' => __( 'Set featured image', 'ax-front' ),
- 'remove_featured_image' => __( 'Remove featured image', 'ax-front' ),
- 'use_featured_image' => __( 'Use as featured image', 'ax-front' ),
- 'insert_into_item' => __( 'Insert into event', 'ax-front' ),
- 'uploaded_to_this_item' => __( 'Uploaded to this event', 'ax-front' ),
- 'items_list' => __( 'Invoices list', 'ax-front' ),
- 'items_list_navigation' => __( 'Invoices list navigation', 'ax-front' ),
- 'filter_items_list' => __( 'Filter Invoices list', 'ax-front' ),
- );
- register_post_type('invoices',
- array(
- 'labels' => $labels,
- 'public' => true,
- 'publicly_queryable' => false,
- 'show_in_rest'=> true,
- 'menu_icon' => "dashicons-media-spreadsheet",
- 'menu_position' => 6,
- 'rewrite' => array(
- 'slug' => 'invoice',
- 'with_front' => false
- ),
- 'supports' => array( 'title' ),
- )
- );
- }
- add_action('init', 'invoice_cpt');
- //Register Expenses CPT
- function expenses_cpt()
- {
- $labels = array(
- 'name' => _x( 'Expenses', 'Post Type General Name', 'ax-front' ),
- 'singular_name' => _x( 'Expense', 'Post Type Singular Name', 'ax-front' ),
- 'menu_name' => __( 'Expenses', 'ax-front' ),
- 'name_admin_bar' => __( 'Expense', 'ax-front' ),
- 'archives' => __( 'Expense Archives', 'ax-front' ),
- 'attributes' => __( 'Expense Attributes', 'ax-front' ),
- 'parent_item_colon' => __( 'Parent Expense:', 'ax-front' ),
- 'all_items' => __( 'All Expenses', 'ax-front' ),
- 'add_new_item' => __( 'Add New Expense', 'ax-front' ),
- 'add_new' => __( 'Add New', 'ax-front' ),
- 'new_item' => __( 'New Expense', 'ax-front' ),
- 'edit_item' => __( 'Edit Expense', 'ax-front' ),
- 'update_item' => __( 'Update Expense', 'ax-front' ),
- 'view_item' => __( 'View Expense', 'ax-front' ),
- 'view_items' => __( 'View Expense', 'ax-front' ),
- 'search_items' => __( 'Search Expense', 'ax-front' ),
- 'not_found' => __( 'Not found', 'ax-front' ),
- 'not_found_in_trash' => __( 'Not found in Trash', 'ax-front' ),
- 'featured_image' => __( 'Featured Image', 'ax-front' ),
- 'set_featured_image' => __( 'Set featured image', 'ax-front' ),
- 'remove_featured_image' => __( 'Remove featured image', 'ax-front' ),
- 'use_featured_image' => __( 'Use as featured image', 'ax-front' ),
- 'insert_into_item' => __( 'Insert into event', 'ax-front' ),
- 'uploaded_to_this_item' => __( 'Uploaded to this event', 'ax-front' ),
- 'items_list' => __( 'Expenses list', 'ax-front' ),
- 'items_list_navigation' => __( 'Expenses list navigation', 'ax-front' ),
- 'filter_items_list' => __( 'Filter Expenses list', 'ax-front' ),
- );
- register_post_type('expenses',
- array(
- 'labels' => $labels,
- 'public' => true,
- 'publicly_queryable' => false,
- 'show_in_rest'=> true,
- 'menu_icon' => "dashicons-tickets-alt",
- 'menu_position' => 6,
- 'rewrite' => array(
- 'slug' => 'expense',
- 'with_front' => false
- ),
- 'supports' => array( 'title' ),
- )
- );
- }
- add_action('init', 'expenses_cpt');
- //custom functions
- function get_block( $post_id, $block_name ) {
- //get post_content for page
- $post_content = get_post( $post_id )->post_content;
- //get all blocks of requested type
- $blocks = array_filter( parse_blocks( $post_content ), function( $block ) use( $block_name ) {
- return $block_name === $block['blockName'];
- });
- $block_content = '';
- foreach( $blocks as $block ) {
- $block_content .= render_block( $block );
- }
- return $block_content;
- }
- function get_block_field( $post_id, $block_name, $field ) {
- //get post_content for page
- $post_content = get_post( $post_id )->post_content;
- //get all blocks of requested type
- $blocks = array_filter( parse_blocks( $post_content ), function( $block ) use( $block_name ) {
- return $block_name === $block['blockName'];
- });
- foreach ($blocks as $block) {
- $field_data = $block['attrs']['data'][$field];
- }
- return $field_data;
- }
- //add options page
- if( function_exists('acf_add_options_page') ) {
- acf_add_options_page(array(
- 'page_title' => 'Global Settings',
- 'menu_title' => 'Global Settings',
- 'menu_slug' => 'global-settings',
- 'capability' => 'edit_posts',
- 'redirect' => false
- ));
- }
- function enqueue() {
- wp_register_script( 'jszip', plugin_dir_url( __FILE__ ).'/js/jszip.min.js', array('jquery'), '', true );
- wp_register_script( 'jszip-utils', plugin_dir_url( __FILE__ ).'/js/jszip-utils.min.js', array('jquery'), '', true );
- wp_register_script( 'filesaver', plugin_dir_url( __FILE__ ).'/js/FileSaver.min.js', array('jquery'), '', true );
- wp_register_script( 'admin-links', plugin_dir_url( __FILE__ ).'/js/admin-links.js', array('jquery'), '', true );
- wp_localize_script( 'admin-links', 'myAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' )));
- wp_register_script( 'admin-publishers', plugin_dir_url( __FILE__ ).'/js/admin-publishers.js', array('jquery'), '', true );
- wp_localize_script( 'admin-publishers', 'myAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' )));
- wp_register_script( 'chosen-js', plugin_dir_url( __FILE__ ).'/js/chosen.jquery.min.js', array('jquery'), '', true );
- wp_enqueue_script( 'jquery' );
- wp_enqueue_script( 'jszip' );
- wp_enqueue_script( 'jszip-utils' );
- wp_enqueue_script( 'filesaver' );
- wp_enqueue_script( 'admin-links' );
- wp_enqueue_script( 'admin-publishers' );
- wp_enqueue_script( 'chosen-js' );
- wp_enqueue_style( 'admin-css', plugin_dir_url( __FILE__ ).'/css/admin-css.css' );
- wp_enqueue_style( 'chosen-css', plugin_dir_url( __FILE__ ).'/css/chosen.min.css' );
- }
- add_action( 'admin_enqueue_scripts', 'enqueue', 100 );
- function enqueue_publishers_scripts(){
- wp_enqueue_script( 'publisher_datatables', plugin_dir_url( __FILE__ ).'/js/publishertable.js', array('jquery'), '', true );
- wp_localize_script( 'publisher_datatables', 'ajax_url', admin_url('admin-ajax.php?action=publisher_datatables') );
- }
- function enqueue_orders_scripts(){
- wp_enqueue_script( 'orders_datatables', plugin_dir_url( __FILE__ ).'/js/orderstable.js', array('jquery'), '', true );
- wp_localize_script( 'orders_datatables', 'ajax_url', admin_url('admin-ajax.php?action=orders_datatables') );
- }
- add_action( 'template_redirect', function(){
- if(is_page('publishers') || is_page('favourites')){
- add_action( 'wp_enqueue_scripts', 'enqueue_publishers_scripts' );
- }else if(is_page('orders')){
- add_action( 'wp_enqueue_scripts', 'enqueue_orders_scripts' );
- }
- } );
- //Populate Links select fields
- function load_publisher_choices( $field ) {
- $field['choices'] = array();
- $publishers = get_posts([
- 'post_type' => 'publisher',
- 'post_status' => 'publish',
- 'numberposts' => -1
- ]);
- $field['choices'][] = 'Select a publisher';
- foreach($publishers as $publisher) {
- $value = $publisher->ID;
- $label = get_field("domain", $publisher->ID);
- $field['choices'][ $value ] = $label;
- }
- return $field;
- }
- add_filter('acf/load_field/name=publisher', 'load_publisher_choices');
- function load_source_choices( $field ) {
- $field['choices'] = array();
- $sources = get_terms(array(
- 'taxonomy' => 'source',
- 'hide_empty' => false
- ));
- $field['choices'][] = 'Select a source';
- foreach($sources as $source) {
- $value = $source->term_id;
- $label = $source->name;
- $field['choices'][ $value ] = $label;
- }
- return $field;
- }
- add_filter('acf/load_field/name=source', 'load_source_choices');
- function load_client_choices( $field ) {
- $field['choices'] = array();
- $args = array(
- 'role__in' => [ 'links_client', 'monthly_client', 'administrator' ],
- 'orderby' => 'user_nicename',
- 'order' => 'ASC'
- );
- $clients = get_users( $args );
- $field['choices'][] = 'Select a client';
- foreach($clients as $client) {
- $value = $client->ID;
- $company = get_user_meta($client->ID, "company", true);
- $field['choices'][ $value ] = $company;
- }
- return $field;
- }
- add_filter('acf/load_field/name=client', 'load_client_choices');
- function load_writer_choices( $field ) {
- $field['choices'] = array();
- $args = array(
- 'role__in' => [ 'writer' ],
- 'orderby' => 'user_nicename',
- 'order' => 'ASC'
- );
- $writers = get_users( $args );
- $field['choices'][] = 'Select a writer';
- foreach($writers as $writer) {
- $value = $writer->ID;
- $label = $writer->display_name;
- $field['choices'][ $value ] = $label;
- }
- return $field;
- }
- add_filter('acf/load_field/name=writer', 'load_writer_choices');
- function load_invoice_choices( $field ) {
- $field['choices'] = array();
- $invoices = get_posts([
- 'post_type' => 'invoices',
- 'post_status' => 'publish',
- 'numberposts' => -1
- ]);
- $field['choices'][] = 'Select an invoice no.';
- foreach($invoices as $invoice) {
- $value = $invoice->ID;
- $invoice_no = get_post_meta( $invoice->ID , 'invoice_no' , true );
- $label = $invoice_no;
- $field['choices'][ $value ] = $label;
- }
- return $field;
- }
- add_filter('acf/load_field/name=invoice_no', 'load_invoice_choices');
- //Populate Tasks select fields
- function load_link_choices( $field ) {
- $field['choices'] = array();
- $links = get_posts([
- 'post_type' => 'link',
- 'post_status' => 'publish',
- 'numberposts' => -1
- ]);
- $field['choices'][] = 'Select a link';
- foreach($links as $link) {
- $value = $link->ID;
- $label = $link->post_title;
- $field['choices'][ $value ] = $label;
- }
- return $field;
- }
- add_filter('acf/load_field/name=link', 'load_link_choices');
- //Populate client publisher categories
- function load_publisher_categories_choices( $field ) {
- $field['choices'] = array();
- $publisher_categories = get_terms([
- 'taxonomy' => 'category',
- 'hide_empty' => 'false',
- ]);
- foreach($publisher_categories as $category) {
- $value = $category->name;
- $label = $category->name;
- $field['choices'][ $value ] = $label;
- }
- return $field;
- }
- add_filter('acf/load_field/name=publisher_categories', 'load_publisher_categories_choices');
- function acf_disabled($field) {
- $post = get_post();
- $field['disabled'] = 1;
- return $field;
- }
- function acf_readonly($field) {
- $post = get_post();
- $field['readonly'] = 1;
- return $field;
- }
- add_filter('acf/load_field/name=publisher_fee', 'acf_readonly');
- add_filter('acf/load_field/name=client_price', 'acf_readonly');
- add_filter('acf/load_field/name=unique_code', 'acf_disabled');
- add_filter('acf/load_field/name=date_updated', 'acf_disabled');
- add_filter('acf/load_field/name=writer_cost', 'acf_readonly');
- add_filter('acf/load_field/name=publisher_requirements_links', 'acf_readonly');
- //User management
- function add_roles() {
- add_role( 'links_client', 'Links Client', array( 'read' => true, 'level_0' => true ) );
- add_role( 'monthly_client', 'Monthly SEO Client', array( 'read' => true, 'level_0' => true ) );
- add_role( 'writer', 'Writer', array( 'read' => true, 'level_0' => true ) );
- add_role( 'freelancer', 'Freelancer', array( 'read' => true, 'level_0' => true ) );
- }
- add_action( 'init', 'add_roles' );
- function add_theme_caps() {
- $writer = get_role( 'writer' );
- $writer->add_cap( 'edit_link' );
- $writer->add_cap( 'edit_links' );
- $writer->add_cap( 'edit_other_links' );
- // $writer->add_cap( 'publish_links' );
- $writer->add_cap( 'read_link' );
- $writer->add_cap( 'read_private_links' );
- $writer->add_cap( 'delete_link' );
- $writer->add_cap( 'delete_links' );
- $writer->remove_cap( 'publish_links' );
- $freelancer = get_role( 'freelancer' );
- $freelancer->add_cap( 'edit_link' );
- $freelancer->add_cap( 'edit_links' );
- $freelancer->add_cap( 'edit_other_links' );
- $freelancer->add_cap( 'publish_links' );
- $freelancer->add_cap( 'read_link' );
- $freelancer->add_cap( 'read_private_links' );
- $freelancer->add_cap( 'delete_link' );
- $freelancer->add_cap( 'delete_links' );
- $admin = get_role( 'administrator' );
- $admin->add_cap( 'edit_task' );
- $admin->add_cap( 'edit_tasks' );
- $admin->add_cap( 'edit_other_tasks' );
- $admin->add_cap( 'publish_tasks' );
- $admin->add_cap( 'read_task' );
- $admin->add_cap( 'read_private_tasks' );
- $admin->add_cap( 'delete_task' );
- $admin->add_cap( 'delete_tasks' );
- $admin->add_cap( 'edit_link' );
- $admin->add_cap( 'edit_links' );
- $admin->add_cap( 'edit_other_links' );
- $admin->add_cap( 'publish_links' );
- $admin->add_cap( 'read_link' );
- $admin->add_cap( 'read_private_links' );
- $admin->add_cap( 'delete_link' );
- $admin->add_cap( 'delete_links' );
- }
- add_action( 'admin_init', 'add_theme_caps');
- //show only links assigned to current writer
- function only_show_assigned_links($query) {
- // Make sure we're in the admin and it's the main query
- if ( !is_admin() && !$query->is_main_query() ) {
- return;
- }
- if ( !in_array( 'writer', (array) wp_get_current_user()->roles ) ) {
- return;
- }
- global $typenow;
- // Only do this for pages
- if ( 'link' == $typenow) {
- if(get_current_screen()->id != 'link'){
- $previous_meta_query = $query->get('meta_query');
- array_push($previous_meta_query, array(
- 'relation' => 'AND',
- array(
- 'key' => 'writer',
- 'value' => get_current_user_id(),
- 'compare' => '='
- ),
- array(
- 'key' => 'status',
- 'value' => array('Article Ordered', 'To Improve'),
- 'compare' => 'IN'
- )
- ));
- $query->set('meta_query', $previous_meta_query);
- }
- return;
- }
- }
- add_action('pre_get_posts', 'only_show_assigned_links');
- //freelancer show only links in his region
- function only_show_region_links($query) {
- // Make sure we're in the admin and it's the main query
- if ( !is_admin() && !$query->is_main_query() ) {
- return;
- }
- if ( !in_array( 'freelancer', (array) wp_get_current_user()->roles ) ) {
- return;
- }
- //get assigned market to current freelancer
- $markets = get_user_meta(get_current_user_ID(), "markets", true);
- global $typenow;
- // Only do this for pages
- if ( 'link' == $typenow) {
- if(get_current_screen()->id != 'link'){
- $query->set( 'meta_query', array(
- array(
- 'key' => 'market',
- 'value' => $markets,
- 'compare' => 'IN',
- )
- ) );
- }
- return;
- }
- }
- add_action('pre_get_posts', 'only_show_region_links');
- //hide fields for writer
- function writer_hide_fields($field) {
- $post = get_post();
- if ( in_array( 'writer', (array) wp_get_current_user()->roles ) ) {
- return null;
- }
- return $field;
- }
- add_filter('acf/load_field/name=client', 'writer_hide_fields');
- add_filter('acf/load_field/name=publisher', 'writer_hide_fields');
- add_filter('acf/load_field/name=publisher_fee', 'writer_hide_fields');
- add_filter('acf/load_field/name=source', 'writer_hide_fields');
- add_filter('acf/load_field/name=link_type', 'writer_hide_fields');
- add_filter('acf/load_field/name=writer_cost', 'writer_hide_fields');
- add_filter('acf/load_field/name=writer_paid', 'writer_hide_fields');
- add_filter('acf/load_field/name=author', 'writer_hide_fields');
- // add_filter('acf/load_field/name=assets', 'writer_hide_fields');
- add_filter('acf/load_field/name=guest_post', 'writer_hide_fields');
- add_filter('acf/load_field/name=client_price', 'writer_hide_fields');
- add_filter('acf/load_field/name=our_discounted_fee', 'writer_hide_fields');
- add_filter('acf/load_field/name=invoice_no', 'writer_hide_fields');
- add_filter('acf/load_field/name=writer', 'writer_hide_fields');
- add_filter('acf/load_field/name=publisher_paid', 'writer_hide_fields');
- add_filter('acf/load_field/name=notes', 'writer_hide_fields');
- add_filter('acf/load_field/name=market', 'writer_hide_fields');
- add_filter('acf/load_field/name=client_url_2', 'writer_hide_fields');
- //hide fields for freelancer
- function freelancer_hide_fields($field) {
- $post = get_post();
- if ( in_array( 'freelancer', (array) wp_get_current_user()->roles ) ) {
- return null;
- }
- return $field;
- }
- add_filter('acf/load_field/name=market', 'freelancer_hide_fields');
- //read only
- function writer_read_only($field) {
- $post = get_post();
- if(!empty($post)){
- if($post->post_type == 'link'){
- if ( in_array( 'writer', (array) wp_get_current_user()->roles ) ) {
- $field['disabled'] = 1;
- $field['disabled'] = array(
- 'approve',
- 'improve',
- );
- return $field;
- }
- }
- }
- return $field;
- }
- add_filter('acf/load_field/name=anchor_text', 'writer_read_only');
- add_filter('acf/load_field/name=anchor_text_2', 'writer_read_only');
- add_filter('acf/load_field/name=date_live', 'writer_read_only');
- add_filter('acf/load_field/name=word_count', 'writer_read_only');
- add_filter('acf/load_field/name=client_url', 'writer_read_only');
- add_filter('acf/load_field/name=live_url', 'writer_read_only');
- add_filter('acf/load_field/name=article_title', 'writer_read_only');
- add_filter('acf/load_field/name=improvement_comments', 'writer_read_only');
- // add_filter('acf/load_field/name=status', 'writer_read_only');
- add_filter('acf/load_field/name=approve_improve', 'writer_read_only');
- add_filter('acf/load_field/name=link_in', 'writer_read_only');
- add_filter('acf/load_field/name=notes_to_writer', 'writer_read_only');
- add_filter('acf/load_field/name=date_updated', 'writer_read_only');
- add_filter('acf/load_field/name=unique_code', 'writer_read_only');
- add_filter('acf/load_field/name=article_document', 'writer_read_only');
- add_filter('acf/load_field/name=invoice_url', 'writer_read_only');
- // Restrict entire pages for logged in users only
- function restrict_page_to_logged_in_user() {
- // Get global post
- global $post;
- $user = wp_get_current_user();
- $restricted_pages = array();
- array_push($restricted_pages,
- "publishers",
- "tasks",
- "black-list",
- "favourites",
- "requests",
- "invoices",
- "orders"
- );
- $redirect = true;
- $post_slug = $post->post_name;
- if(is_page() && in_array($post_slug, $restricted_pages)){
- if ( is_user_logged_in() ) {
- if ( in_array( 'administrator', (array) $user->roles ) ) {
- $redirect = false;
- }
- if ( in_array( 'links_client', (array) $user->roles ) ) {
- $redirect = false;
- }
- if ( in_array( 'monthly_client', (array) $user->roles ) ) {
- if($post_slug == 'orders'){
- $redirect = false;
- }
- }
- }
- }else {
- $redirect = false;
- }
- // foreach ($restricted_pages as $page){
- // $page_id = get_page_by_path($page)->ID;
- // if ( is_page() && ( $post->post_parent == $page_id || is_page( $page_id ) ) ) {
- // // Set redirect to true by default
- // // If logged in do nor redirect
- // // You can/should place additional checks here based on user roles or user meta
- // if ( is_user_logged_in() ) {
- // if ( in_array( 'administrator', (array) $user->roles ) ) {
- // $redirect = false;
- // }
- // if ( in_array( 'links_client', (array) $user->roles ) ) {
- // $redirect = false;
- // }
- // }
- // }
- // }
- // Redirect people witout access to homepage
- if ( $redirect ) {
- wp_redirect( esc_url( home_url( '/' ) ), 307 );
- }
- }
- add_action( 'template_redirect', 'restrict_page_to_logged_in_user' );
- // function add_roles() {
- // add_role( 'user_download', 'User Download', array( 'read' => true, 'level_0' => true ) );
- // add_role( 'user', 'User', array( 'read' => true, 'level_0' => true ) );
- // }
- // add_action( 'init', 'add_roles' );
- function remove_admin_bar() {
- if (current_user_can('links_client') || current_user_can('monthly_client') && !is_admin()) {
- show_admin_bar(false);
- }
- }
- add_action('after_setup_theme', 'remove_admin_bar');
- add_action('wp_logout','logout');
- function logout(){
- wp_redirect( home_url() );
- exit();
- }
- //remove logout confirmation
- add_action('check_admin_referer', 'logout_without_confirm', 10, 2);
- function logout_without_confirm($action, $result) {
- // Allow logout without confirmation
- if ($action == "log-out" && !isset($_GET['_wpnonce'])) {
- $redirect_to = isset($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : '';
- $location = str_replace('&', '&', wp_logout_url($redirect_to));;
- header("Location: $location");
- die;
- }
- }
- function force_post_categ_init()
- {
- wp_enqueue_script('jquery');
- }
- function force_post_categ()
- {
- echo "<script type='text/javascript'>\n";
- echo "
- jQuery('#publish').click(function()
- {
- var cats = jQuery('[id^=\"source\"]')
- .find('.selectit')
- .find('input');
- category_selected=false;
- for (counter=0; counter<cats.length; counter++)
- {
- if (cats.get(counter).checked==true)
- {
- category_selected=true;
- break;
- }
- }
- if(cats.length){
- if(category_selected==false)
- {
- alert('You have not selected any Source for the Link. Please select a Source.');
- setTimeout(\"jQuery('#ajax-loading').css('visibility', 'hidden');\", 100);
- jQuery('[id^=\"taxonomy\"]').find('.tabs-panel').css('background', '#F96');
- setTimeout(\"jQuery('#publish').removeClass('button-primary-disabled');\", 100);
- return false;
- }
- }
- var publisherCats = jQuery('[id^=\"categorychecklist\"]')
- .find('.selectit')
- .find('input');
- category_selected=false;
- for (counter=0; counter<publisherCats.length; counter++)
- {
- if (publisherCats.get(counter).checked==true)
- {
- category_selected=true;
- break;
- }
- }
- if(publisherCats.length){
- if(category_selected==false)
- {
- alert('You have not selected any Category for the Publisher. Please select a Category.');
- setTimeout(\"jQuery('#ajax-loading').css('visibility', 'hidden');\", 100);
- jQuery('[id^=\"taxonomy\"]').find('.tabs-panel').css('background', '#F96');
- setTimeout(\"jQuery('#publish').removeClass('button-primary-disabled');\", 100);
- return false;
- }
- }
- });
- ";
- echo "</script>\n";
- }
- add_action('admin_init', 'force_post_categ_init');
- add_action('edit_form_advanced', 'force_post_categ');
- //remove Add New Links Button
- function disable_new_posts() {
- // Hide sidebar link
- // global $submenu;
- // unset($submenu['post-new.php?post_type=link'][10]);
- // Hide link on listing page
- if ( in_array( 'writer', (array) wp_get_current_user()->roles ) ) {
- echo '<style type="text/css">
- .page-title-action { display: none }
- #menu-posts-link .wp-submenu li:last-child { display: none }
- </style>';
- }
- }
- add_action('admin_init', 'disable_new_posts');
- //update prices when publisher is updated
- // add_action('save_post_publisher', 'update_publisher_prices', 10, 3);
- // function update_publisher_prices($post_ID, $post_after, $post_before){
- // $links_assigned_to_publisher = get_posts(
- // array(
- // 'post_type' => 'link',
- // 'numberposts' => -1,
- // 'meta_query' => array(
- // array(
- // 'key' => 'publisher',
- // 'value' => $post_ID,
- // 'compare' => '=',
- // )
- // )
- // )
- // );
- // var_dump($post_after);
- // var_dump($links_assigned_to_publisher);
- // foreach($links_assigned_to_publisher as $link) {
- // //our fee
- // $our_fee = get_field("fee", $post_ID);
- // $market = get_field("market", $link->ID);
- // var_dump($our_fee);
- // var_dump($market);
- // }
- // die();
- // }
- add_action('updated_post_meta', 'update_publisher_prices', 10, 4);
- function update_publisher_prices($meta_id, $object_id, $meta_key, $meta_value){
- // if($meta_key == "fee"){
- // $links_assigned_to_publisher = get_posts(
- // array(
- // 'post_type' => 'link',
- // 'numberposts' => -1,
- // 'meta_query' => array(
- // array(
- // 'key' => 'publisher',
- // 'value' => $object_id,
- // 'compare' => '=',
- // )
- // )
- // )
- // );
- // if(isset($links_assigned_to_publisher)){
- // foreach($links_assigned_to_publisher as $link) {
- // //our fee
- // $our_fee = $meta_value;
- // $market = get_field("market", $link->ID);
- // if($market == "EN"){
- // $total_fee = $our_fee + 150;
- // }else {
- // $total_fee = $our_fee+ 220;
- // }
- // update_field("client_price", $total_fee, $link->ID);
- // }
- // }
- // }
- if($meta_key == "publisher_fees"){
- $links_assigned_to_publisher = get_posts(
- array(
- 'post_type' => 'link',
- 'numberposts' => -1,
- 'meta_query' => array(
- array(
- 'key' => 'publisher',
- 'value' => $object_id,
- 'compare' => '=',
- )
- )
- )
- );
- if(isset($links_assigned_to_publisher)){
- foreach($links_assigned_to_publisher as $link) {
- //our fee
- $publisher_fees = $meta_value;
- update_field("publisher_fee", $publisher_fees, $link->ID);
- }
- }
- }
- }
- //create ajax function to check blacklist
- add_action("wp_ajax_check_black_list", "check_black_list");
- function check_black_list() {
- if(isset($_REQUEST["publisher_url"]) && isset($_REQUEST["url"]) && isset($_REQUEST["client_id"])){
- $args = array(
- 'numberposts' => -1,
- 'post_type'=> 'link',
- 'meta_query' => array(
- 'relation' => 'AND',
- array(
- 'key' => 'publisher',
- 'value' => $_REQUEST['publisher_url'],
- 'type' => 'numeric',
- 'compare' => 'IN',
- ),
- array(
- 'key' => 'client',
- 'value' => $_REQUEST['client_id'],
- 'type' => 'numeric',
- 'compare' => 'IN',
- ),
- )
- );
- $links = get_posts($args);
- $publisher_url = get_field("domain", $_REQUEST["publisher_url"] );
- $publisher_url = strip_url($publisher_url);
- $inputted_url = $_REQUEST["url"];
- $inputted_url = strip_url($inputted_url);
- $connection_exists = false;
- foreach($links as $link){
- $client_url = get_field("client_url", $link->ID);
- $client_url = strip_url($client_url);
- $result["inputted_url"] = $inputted_url;
- $result["client_url"] = $client_url;
- if($inputted_url == $client_url){
- $connection_exists = true;
- }
- }
- //check in blacklist
- //get blacklist for user
- $blacklist = get_user_meta($_REQUEST["client_id"], 'blacklist', true);
- $result["blacklist"] = $blacklist;
- $result["publisher_url"] = $publisher_url;
- $result["inputted_url"] = $inputted_url;
- foreach($blacklist as $list_item){
- $item_publisher = $list_item["publisher_url"];
- $item_publisher = strip_url($item_publisher);
- $item_website = $list_item["website"];
- $item_website = strip_url($item_website);
- if(($item_publisher == $publisher_url) && (strpos($inputted_url, $item_website) !== false)){
- $connection_exists = true;
- }
- }
- $result["connection_exists"] = $connection_exists;
- }
- $result['type'] = "success";
- if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
- $result = json_encode($result);
- echo $result;
- }
- else {
- header("Location: ".$_SERVER["HTTP_REFERER"]);
- }
- die();
- }
- function strip_url($url){
- $url = strip_tags($url);
- $url = str_replace("https://", "", $url);
- $url = str_replace("www.", "", $url);
- $url = str_replace("http://", "", $url);
- $url = str_replace("/", "", $url);
- $url = str_replace(" ", "", $url);
- $url = preg_replace('/\s/', '', $url);
- return $url;
- }
- // Add Post title to custom meta
- add_action( 'transition_post_status', 'duplicate_title', 10, 3 );
- function duplicate_title( $new, $old, $post ) {
- if ( $post->post_type == 'publisher' ) {
- update_post_meta( $post->ID, 'd_title', $post->post_title );
- }
- }
- add_action('wp_ajax_publisher_datatables', 'datatables_server_side_callback');
- add_action('wp_ajax_nopriv_publisher_datatables', 'datatables_server_side_callback');
- function datatables_server_side_callback() {
- header("Content-Type: application/json");
- $request= $_GET;
- $meta_query = [];
- $tax_query = [];
- if(isset($request)){
- if(isset($request['country'])){
- $meta_query[] = array(
- 'key' => 'country',
- 'value' => $request['country'],
- );
- }
- if(isset($request['url'])){
- $meta_query[] = array(
- 'key' => 'domain',
- 'value' => $request['url'],
- 'compare' => 'LIKE',
- );
- }
- if(isset($request['language'])){
- if(!empty($request['language'])){
- $meta_query[] = array(
- 'key' => 'language',
- 'value' => $request['language'],
- 'compare' => 'LIKE',
- );
- }
- }
- if(isset($request['links'])){
- if(!empty($request['links'])){
- $meta_query[] = array(
- 'key' => 'link_type',
- 'value' => $request['links'],
- );
- }
- }
- if(isset($request['traffic'])){
- $traffic_exploded = explode("-", $request['traffic']);
- if(count($traffic_exploded) > 1){
- $meta_query[] = array(
- 'key' => 'organic_traffic',
- 'value' => array($traffic_exploded[0], $traffic_exploded[1]),
- 'type' => 'numeric',
- 'compare' => 'BETWEEN',
- );
- }
- }
- if(isset($request['dr-min']) && isset($request['dr-max'])){
- if($request['dr-min'] != ''){
- $meta_query[] = array(
- 'key' => 'dr',
- 'value' => $request['dr-min'],
- 'type' => 'numeric',
- 'compare' => '>=',
- );
- }
- if($request['dr-max'] != ''){
- $meta_query[] = array(
- 'key' => 'dr',
- 'value' => $request['dr-max'],
- 'type' => 'numeric',
- 'compare' => '<=',
- );
- }
- }
- if(isset($request['rd-min']) && isset($request['rd-max'])){
- if(($request['rd-min'] != '') && ($request['rd-max'] != '')){
- $meta_query[] = array(
- 'key' => 'rd',
- 'value' => array($request['rd-min'], $request['rd-max']),
- 'type' => 'numeric',
- 'compare' => 'BETWEEN',
- );
- }
- }
- if(isset($request['price-min']) && isset($request['price-max'])){
- if($request['price-min'] != ''){
- $meta_query[] = array(
- 'key' => 'fee',
- 'value' => $request['price-min'],
- 'type' => 'numeric',
- 'compare' => '>=',
- );
- }
- if($request['price-max'] != ''){
- $meta_query[] = array(
- 'key' => 'fee',
- 'value' => $request['price-max'],
- 'type' => 'numeric',
- 'compare' => '<=',
- );
- }
- }
- if(isset($request['tf-min']) && isset($request['tf-max'])){
- if(($request['tf-min'] != '') && ($request['tf-max'] != '')){
- $meta_query[] = array(
- 'key' => 'tf',
- 'value' => array($request['tf-min'], $request['tf-max']),
- 'type' => 'numeric',
- 'compare' => 'BETWEEN',
- );
- }
- }
- //get categories assigned to user
- $user_categories = get_field("publisher_categories", "user_".get_current_user_id());
- if(!empty($user_categories)){
- $tax_query[] = array(
- 'taxonomy' => 'category',
- 'field' => 'slug',
- 'terms' => $user_categories,
- 'operator' => 'IN',
- );
- }
- if(isset($request['category'])){
- $tax_query[] = array(
- 'taxonomy' => 'category',
- 'field' => 'name',
- 'terms' => $request['category'],
- 'operator' => 'IN',
- );
- }
- }
- $date_query = array();
- if(isset($request['date-min'])){
- $date_min = strtotime($request['date-min']);
- if(($request['date-min'] != '')){
- $date_query["after"] = array(
- "year" => date('Y', $date_min),
- "month" => date('m', $date_min),
- "day" => date('d', $date_min),
- );
- }
- }
- if(isset($request['date-max'])){
- $date_max = strtotime($request['date-max']);
- if(($request['date-max'] != '')){
- $date_query["before"] = array(
- "year" => date('Y', $date_max),
- "month" => date('m', $date_max),
- "day" => date('d', $date_max),
- );
- }
- }
- $columns = array(
- 0 => 'domain',
- 1 => 'dr',
- 2 => 'rd',
- 3 => 'organic_traffic',
- 5 => 'language',
- 6 => 'link_type',
- 7 => 'fee',
- );
- $args = array(
- 'post_type' => 'publisher',
- 'post_status' => 'publish',
- 'posts_per_page' => $request['length'],
- 'offset' => $request['start'],
- 'order' => $request['order'][0]['dir'],
- 'meta_query' => $meta_query,
- 'tax_query' => $tax_query,
- );
- if ($request['order'][0]['column'] == 0 || $request['order'][0]['column'] == 5 || $request['order'][0]['column'] == 6) {
- $args['orderby'] = 'meta_value';
- $args['meta_key'] = $columns[$request['order'][0]['column']];
- } elseif ($request['order'][0]['column'] == 1 || $request['order'][0]['column'] == 2 || $request['order'][0]['column'] == 3 || $request['order'][0]['column'] == 7) {
- $args['orderby'] = 'meta_value_num';
- $args['meta_key'] = $columns[$request['order'][0]['column']];
- }
- $current_user = wp_get_current_user();
- $previous_favs = get_user_meta($current_user->ID, 'fav_publishers', true);
- if($request['favs_only'] == 1){
- if(empty($previous_favs)){
- $previous_favs = array(-1);
- }
- $args['post__in'] = $previous_favs;
- }
- $publisher_query = new WP_Query($args);
- $totalData = $publisher_query->found_posts;
- $currency = get_field("currency", "user_".$current_user->ID);
- if(empty($currency)){
- $currency = "€";
- }
- $allowDomainViewFav = get_field("allow_domain_name_view_fav", "user_".$current_user->ID);
- $allowDomainViewPub = get_field("allow_domain_name_view_publishers", "user_".$current_user->ID);
- if ( $publisher_query->have_posts() ) {
- while ( $publisher_query->have_posts() ) {
- $publisher_query->the_post();
- $hidden_url = str_replace("www.","",( str_replace("https://", "", get_field("domain"))));
- $exploded_url = explode('.', $hidden_url);
- if($request['favs_only'] == 1){
- if ( $allowDomainViewFav != 1 ) {
- $exploded_url[0] = substr($exploded_url[0], 0, 2) . str_repeat("*", strlen($exploded_url[0]) - 2);
- }
- }else {
- if ( $allowDomainViewPub != 1 ) {
- $exploded_url[0] = substr($exploded_url[0], 0, 2) . str_repeat("*", strlen($exploded_url[0]) - 2);
- }
- }
- $hidden_url = implode('.', $exploded_url);
- $domain_html = '<div class="flex items-center justify-between" data-enable-view-fab="'.$allowDomainViewFav.'" data-enable-view-pub="'.$allowDomainViewPub.'">';
- // $domain_html .= '<a target="_blank" class="url" href="'.addhttp(get_field('domain')).'">'.$hidden_url.'</a>';
- $domain_html .= '<p target="_blank" class="url">'.$hidden_url.'</p>';
- $domain_html .= '<form action="" method="POST" >
- <input type="hidden" value="'.get_the_ID().'" name="pub">
- </form>';
- if(empty($previous_favs)){
- $previous_favs = array();
- }
- //check if favourite
- $fav_classes = "";
- if(in_array(get_the_ID(), $previous_favs)){
- $fav_classes .= "selected";
- }
- $domain_html .= '
- <div class="star '.$fav_classes.'" title="ADD TO FAVOURITES" data-publisher="'.get_the_ID().'">
- <svg version="1.1"
- xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
- x="0px" y="0px" width="26.1px" height="24.9px" viewBox="0 0 26.1 24.9"
- style="overflow:scroll;enable-background:new 0 0 26.1 24.9;" xml:space="preserve">
- <style type="text/css">
- .st0{fill:#E9704A00;stroke:#E9704A;stroke-miterlimit:10;transition: fill 0.2s ease;}
- </style>
- <defs>
- </defs>
- <path class="st0" d="M13.6,0.9l3.2,7.5L25,9.1c0.4,0,0.6,0.3,0.6,0.7c0,0.2-0.1,0.3-0.2,0.4l-6.2,5.4l1.9,8c0.1,0.3-0.1,0.7-0.5,0.8
- c-0.2,0-0.3,0-0.5-0.1l-7-4.2l-7,4.2c-0.3,0.2-0.7,0.1-0.9-0.2C5,23.9,5,23.8,5.1,23.6l1.9-8l-6.2-5.4C0.5,10,0.4,9.6,0.7,9.4
- c0.1-0.1,0.3-0.2,0.4-0.2l8.2-0.7l3.2-7.5c0.1-0.3,0.5-0.5,0.8-0.3C13.4,0.6,13.6,0.7,13.6,0.9z"/>
- </svg>
- </div>';
- $domain_html .= '</div>';
- $categories_html = '';
- $categories = get_the_terms(get_the_ID(), 'category');
- $len = count($categories);
- foreach ($categories as $key=>$category) {
- $categories_html.= $category->name;
- if($key !== $len-1){
- $categories_html.= ', ';
- }
- }
- $language_html = '';
- $language = get_field("language");
- if (is_array($language)){
- $language_html .= implode(', ', $language);
- } else {
- $language_html.=$language;
- }
- $links_html= '';
- $link_type = get_field("link_type");
- if (is_array($link_type)){
- $links_html.=$link_type['label'];
- }else{
- $links_html.=$link_type;
- }
- $nestedData = array();
- $nestedData[] = $domain_html;
- $nestedData[] = number_format(get_field('dr'));
- $nestedData[] = number_format(get_field('rd'));
- $nestedData[] = number_format(get_field('organic_traffic'));
- $nestedData[] = $categories_html;
- $nestedData[] = $language_html;
- $nestedData[] = $links_html;
- $nestedData[] = $currency.number_format(get_field('fee'));
- $nestedData[] = '<a href="'.get_permalink().'" class="order">ORDER</a>';
- $data[] = $nestedData;
- }
- wp_reset_query();
- $json_data = array(
- "draw" => intval($request['draw']),
- "recordsTotal" => intval($totalData),
- "recordsFiltered" => intval($totalData),
- "data" => $data
- );
- echo json_encode($json_data);
- } else {
- $json_data = array(
- "data" => array()
- );
- echo json_encode($json_data);
- }
- wp_die();
- }
- add_action('wp_ajax_orders_datatables', 'datatables_server_side_callback_orders');
- add_action('wp_ajax_nopriv_orders_datatables', 'datatables_server_side_callback_orders');
- function datatables_server_side_callback_orders() {
- header("Content-Type: application/json");
- $request= $_GET;
- $columns = array(
- 0 => 'date',
- 1 => 'client_url',
- 2 => 'publisher',
- 3 => 'unique_code',
- 4 => 'client_price',
- 5 => 'anchor_text',
- 6 => 'anchor_text_2',
- 7 => 'live_url',
- 8 => 'status',
- );
- if(App::isMonthlyClient()){
- $columns = array(
- 0 => 'date',
- 1 => 'client_url',
- 2 => 'publisher',
- 3 => 'unique_code',
- 4 => 'anchor_text',
- 5 => 'anchor_text_2',
- 6 => 'live_url',
- 7 => 'status',
- );
- }
- $current_user = wp_get_current_user();
- $meta_query = array(
- 'relation' => 'AND'
- );
- $meta_query[] = array(
- 'key' => 'client',
- 'value' => $current_user->ID,
- );
- if(current_user_can("monthly_client")){
- $meta_query[] = array(
- 'key' => 'status',
- 'value' => array("Pitch Accepted", "Article Ordered", "Article Sent", "Live"),
- 'compare' => 'IN',
- );
- }
- if(!empty($request['search']['value'])){
- $meta_query[] = array(
- 'key' => 'status',
- 'value' => sanitize_text_field($request['search']['value']),
- 'compare' =>'LIKE',
- );
- }
- $args = array(
- 'post_type' => 'link',
- 'post_status' => 'publish',
- 'posts_per_page' => $request['length'],
- 'offset' => $request['start'],
- 'order' => $request['order'][0]['dir'],
- 'meta_query' => $meta_query,
- 'tax_query' => $tax_query
- );
- if ($request['order'][0]['column'] == 1 || $request['order'][0]['column'] == 3 || $request['order'][0]['column'] == 5 || $request['order'][0]['column'] == 6 || $request['order'][0]['column'] == 7 || $request['order'][0]['column'] == 8) {
- $args['orderby'] = 'meta_value';
- $args['meta_key'] = $columns[$request['order'][0]['column']];
- } elseif ( $request['order'][0]['column'] == 4) {
- $args['orderby'] = 'meta_value_num';
- $args['meta_key'] = $columns[$request['order'][0]['column']];
- } elseif ( $request['order'][0]['column'] == 0 ) {
- $args['orderby'] = $columns[$request['order'][0]['column']];
- }elseif ( $request['order'][0]['column'] == 2 ) {
- // $args['orderby'] = get_field('domain', $columns[$request['order'][0]['column']]);
- $args['orderby'] = 'meta_value_num';
- $args['meta_key'] = $columns[$request['order'][0]['column']];
- }
- $orders_query = new WP_Query($args);
- $totalData = $orders_query->found_posts;
- $currency = get_field("currency", "user_".$current_user->ID);
- if(empty($currency)){
- $currency = "€";
- }
- if ( $orders_query->have_posts() ) {
- while ( $orders_query->have_posts() ) {
- $orders_query->the_post();
- $date = DateTime::createFromFormat('Ymd', get_field("date_updated", get_the_ID()));
- $date_formatted = get_field("date_updated", get_the_ID());
- if($date){
- $date_formatted = $date->format('d/m/Y') ;
- }
- $invoice_id = get_field("invoice_no", get_the_ID());
- $invoice_file = get_field("invoice", $invoice_id);
- $invoice_url = $invoice_file["url"];
- //need if here
- $status_html = '<td class="ttu status tr'.(get_field("status", get_the_ID())=='Live') ? "green" : "" .'">'.get_field("status", get_the_ID()).'</td>';
- $nestedData = array();
- $nestedData[] = '<div>'.$date_formatted.'</div>';
- $nestedData[] = '<div>'.get_field('client_url').'</div>';
- $nestedData[] = '<div>'.get_field("domain", get_field("publisher")).'</div>';
- $nestedData[] = '<div class="tc">'.get_field('unique_code').'</div>';
- if(!App::isMonthlyClient()){
- if(get_field('our_discounted_fee')){
- $nestedData[] = '<div class="tc">'.$currency.number_format(get_field('our_discounted_fee')).'</div>';
- }else{
- $nestedData[] = '<div class="tc">'.$currency.number_format(get_field('client_price')).'</div>';
- }
- }
- $nestedData[] = '<div>'.get_field('anchor_text').'</div>';
- $nestedData[] = '<div>'.get_field('anchor_text_2').'</div>';
- $nestedData[] = '<a target="_blank" class="live-url-wrapper" href="'.addhttp(get_field('live_url')).'"><div class="live-url">'.get_field('live_url').'</div></a>';
- $nestedData[] = '<div class="ttu status tr '.(get_field("status") == 'Live' ? "green" : "").' ">'.get_field("status").'</div>';
- $data[] = $nestedData;
- }
- wp_reset_query();
- $json_data = array(
- "draw" => intval($request['draw']),
- "recordsTotal" => intval($totalData),
- "recordsFiltered" => intval($totalData),
- "data" => $data
- );
- echo json_encode($json_data);
- } else {
- $json_data = array(
- "data" => array()
- );
- echo json_encode($json_data);
- }
- wp_die();
- }
- function addhttp($url) {
- if (!preg_match("~^(?:f|ht)tps?://~i", $url)) {
- $url = "http://" . $url;
- }
- return $url;
- }
- add_action( 'load-profile.php', function() {
- if ( !in_array( 'administrator', (array) wp_get_current_user()->roles ) ) {
- remove_menu_page( 'load-profile.php' );
- exit( wp_safe_redirect( admin_url() ) );
- }
- } );
- function hide_personal_options(){
- if ( !in_array( 'administrator', (array) wp_get_current_user()->roles ) ) {
- echo "\n" . '<script type="text/javascript">jQuery(document).ready(function($) { $(\'#menu-users\').hide(); });</script>' . "\n";
- }
- }
- add_action('admin_head','hide_personal_options');
- add_filter('disable_categories_dropdown', function(){
- return true;
- });
- include 'inc/admin-filters.php';
- include 'inc/admin-columns.php';
- include 'inc/admin-links.php';
- include 'inc/admin-publishers.php';
- // include 'css/admin-css.php';
- // wp_enqueue_style( 'seo-keen', plugins_url( '/css/admin.css', __FILE__ ) );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement